package com.hjy.pojo;

import lombok.Data;

//统一返回结果的类
public class R {

    private Integer code;

    private String message;

    private Object data;

    //把构造方法私有
    private R() {}

    public Integer getCode() {
        return code;
    }

    public R setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public R setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getData() {
        return data;
    }

    public R setData(Object data) {
        this.data = data;
        return this;
    }

    //成功静态方法
    public static R ok() {
        R r = new R();
        r.setCode(200);
        r.setMessage("成功");
        return r;
    }
    public static R ok(Object data) {
        R r = new R();
        r.setCode(200);
        r.setMessage("成功");
        r.setData(data);
        return r;
    }
    //失败静态方法
    public static R error() {
        R r = new R();
        r.setCode(500);
        r.setMessage("失败");
        return r;
    }
    public static R error(Object data) {
        R r = new R();
        r.setCode(500);
        r.setMessage("失败");
        r.setData(data);
        return r;
    }
}
